<template>
	<view class="ys">
		<yHeader :title="tList[type]" :topBg="topBg" :showLeft="false"></yHeader>
		<view class="main">
			<tHome v-if="type == 'home'" :usertype="usertype"></tHome>
			<yMsg v-if="type == 'msg'" :usertype="usertype"></yMsg>
			<tUser v-if="type == 'mine'" :avatar="avatar" :username="username" :usertype="usertype"></tUser>
		</view>
		<yFooter ref="footer"></yFooter>
	</view>
</template>

<script>
	import {
		loginUser,
		msgcount
	} from "@/api/api.js"
	export default {
		data() {
			return {
				type: 'home',
				topBg: '',
				tList: {
					home: '首页',
					msg: '消息',
					mine: '个人中心'
				},
				usertype: 1,
				avatar: '',
				username: ''
			}
		},
		onLoad() {
			this.usertype = uni.getStorageSync('usertype')
			uni.$on('changeType', (e) => {
				this.type = e
			})
		},
		onShow() {
			this.loginUser()
			// this.msgcount()
		},
		onPageScroll(e) {
			if (e.scrollTop > 5) {
				this.topBg = '#fff';
			} else {
				this.topBg = '';
			}
		},
		onUnload() {
			uni.$off()
		},
		methods: {
			msgcount() {
				msgcount({
					msgType: ''
				}).then(res => {

				})
			},
			loginUser() {
				loginUser().then(res => {
					if (res.code == 200) {
						this.avatar = res.data.avatar
						this.username = res.data.nickname
						uni.setStorageSync('avatar', res.data.avatar)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 54px;
	}
</style>